Magic Commands

Please see: http://ipython.readthedocs.io/en/stable/interactive/magics.html for further documentation of Jupyter Notebook/iPython Cell magic commands


In [1]:
%env


Out[1]:
{'Apple_PubSub_Socket_Render': '/private/tmp/com.apple.launchd.K4GurPra4V/Render',
 'CLICOLOR': '1',
 'COLORFGBG': '7;0',
 'COLORTERM': 'truecolor',
 'COMMAND_MODE': 'unix2003',
 'CONDA_DEFAULT_ENV': 'modeling',
 'CONDA_PATH_BACKUP': '/Users/carrie/.rbenv/shims:/Users/carrie/anaconda/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin:/Library/Frameworks/Python.framework/Versions/3.5/bin:/Library/openSSL:/Library/Python/3.5:/Library/:/usr/local/mysql/bin:/Library/Frameworks/Python.framework/Versions/3.5/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/Library/TeX/texbin:/usr/bin:/Users/carrie/anaconda/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/Library/TeX/texbin:/Applications/Postgres.app/Contents/Versions/latest/bin',
 'CONDA_PREFIX': '/Users/carrie/anaconda/envs/modeling',
 'CONDA_PS1_BACKUP': '\\u @ \\w =>',
 'DISPLAY': '/private/tmp/com.apple.launchd.C2Q6tkeNmv/org.macosforge.xquartz:0',
 'EDITOR': '/usr/bin/nano',
 'GIT_PAGER': 'cat',
 'HOME': '/Users/carrie',
 'ITERM_PROFILE': 'Default',
 'ITERM_SESSION_ID': 'w0t0p0:DF8D22DC-BE65-4546-BE03-A7F4671CCDEF',
 'JPY_PARENT_PID': '98240',
 'LANG': 'en_US.UTF-8',
 'LOGNAME': 'carrie',
 'MPLBACKEND': 'module://ipykernel.pylab.backend_inline',
 'OLDPWD': '/Users/carrie/Repo/python',
 'PAGER': 'cat',
 'PATH': '/Users/carrie/anaconda/bin:/Users/carrie/anaconda/envs/modeling/bin:/Users/carrie/.rbenv/shims:/Users/carrie/anaconda/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin:/Library/Frameworks/Python.framework/Versions/3.5/bin:/Library/openSSL:/Library/Python/3.5:/Library/:/usr/local/mysql/bin:/Library/Frameworks/Python.framework/Versions/3.5/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/Library/TeX/texbin:/usr/bin:/Users/carrie/anaconda/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/Library/TeX/texbin:/Applications/Postgres.app/Contents/Versions/latest/bin',
 'PS1': '(modeling) \\u @ \\w =>',
 'PWD': '/Users/carrie/Repo/python/cybersecurity_datascience',
 'RBENV_SHELL': 'bash',
 'SECURITYSESSIONID': '186a8',
 'SHELL': '/bin/bash',
 'SHLVL': '1',
 'SSH_AUTH_SOCK': '/private/tmp/com.apple.launchd.soTIAt9en0/Listeners',
 'TERM': 'xterm-color',
 'TERM_PROGRAM': 'iTerm.app',
 'TERM_PROGRAM_VERSION': '3.1.3',
 'TERM_SESSION_ID': 'w0t0p0:DF8D22DC-BE65-4546-BE03-A7F4671CCDEF',
 'TMPDIR': '/var/folders/71/f03s_jzn5tzcmk06jnlb4h040000gn/T/',
 'USER': 'carrie',
 'XPC_FLAGS': '0x0',
 'XPC_SERVICE_NAME': '0',
 '_': '/Users/carrie/anaconda/bin/jupyter',
 '__CF_USER_TEXT_ENCODING': '0x1F5:0x0:0x0'}

In [2]:
%history


%env
%history

In [3]:
%lsmagic


Out[3]:
Available line magics:
%alias  %alias_magic  %autocall  %automagic  %autosave  %bookmark  %cat  %cd  %clear  %colors  %config  %connect_info  %cp  %debug  %dhist  %dirs  %doctest_mode  %ed  %edit  %env  %gui  %hist  %history  %killbgscripts  %ldir  %less  %lf  %lk  %ll  %load  %load_ext  %loadpy  %logoff  %logon  %logstart  %logstate  %logstop  %ls  %lsmagic  %lx  %macro  %magic  %man  %matplotlib  %mkdir  %more  %mv  %notebook  %page  %pastebin  %pdb  %pdef  %pdoc  %pfile  %pinfo  %pinfo2  %popd  %pprint  %precision  %profile  %prun  %psearch  %psource  %pushd  %pwd  %pycat  %pylab  %qtconsole  %quickref  %recall  %rehashx  %reload_ext  %rep  %rerun  %reset  %reset_selective  %rm  %rmdir  %run  %save  %sc  %set_env  %store  %sx  %system  %tb  %time  %timeit  %unalias  %unload_ext  %who  %who_ls  %whos  %xdel  %xmode

Available cell magics:
%%!  %%HTML  %%SVG  %%bash  %%capture  %%debug  %%file  %%html  %%javascript  %%js  %%latex  %%perl  %%prun  %%pypy  %%python  %%python2  %%python3  %%ruby  %%script  %%sh  %%svg  %%sx  %%system  %%time  %%timeit  %%writefile

Automagic is ON, % prefix IS NOT needed for line magics.

In [4]:
lsmagic


Out[4]:
Available line magics:
%alias  %alias_magic  %autocall  %automagic  %autosave  %bookmark  %cat  %cd  %clear  %colors  %config  %connect_info  %cp  %debug  %dhist  %dirs  %doctest_mode  %ed  %edit  %env  %gui  %hist  %history  %killbgscripts  %ldir  %less  %lf  %lk  %ll  %load  %load_ext  %loadpy  %logoff  %logon  %logstart  %logstate  %logstop  %ls  %lsmagic  %lx  %macro  %magic  %man  %matplotlib  %mkdir  %more  %mv  %notebook  %page  %pastebin  %pdb  %pdef  %pdoc  %pfile  %pinfo  %pinfo2  %popd  %pprint  %precision  %profile  %prun  %psearch  %psource  %pushd  %pwd  %pycat  %pylab  %qtconsole  %quickref  %recall  %rehashx  %reload_ext  %rep  %rerun  %reset  %reset_selective  %rm  %rmdir  %run  %save  %sc  %set_env  %store  %sx  %system  %tb  %time  %timeit  %unalias  %unload_ext  %who  %who_ls  %whos  %xdel  %xmode

Available cell magics:
%%!  %%HTML  %%SVG  %%bash  %%capture  %%debug  %%file  %%html  %%javascript  %%js  %%latex  %%perl  %%prun  %%pypy  %%python  %%python2  %%python3  %%ruby  %%script  %%sh  %%svg  %%sx  %%system  %%time  %%timeit  %%writefile

Automagic is ON, % prefix IS NOT needed for line magics.

In [7]:
%man git

In [8]:
%pwd


Out[8]:
'/Users/carrie/Repo/python/cybersecurity_datascience'

In [9]:
%system


Out[9]:
[]

In [10]:
%time


CPU times: user 2 µs, sys: 1e+03 ns, total: 3 µs
Wall time: 5.01 µs

In [12]:
%timeit
print('Hello')


Hello

In [14]:
%profile


default
/Users/carrie/anaconda/envs/mlbook/lib/python3.5/site-packages/IPython/core/magics/basic.py:298: UserWarning: %profile is now deprecated. Please use get_ipython().profile instead.
  warn("%profile is now deprecated. Please use get_ipython().profile instead.")

In [18]:
%%bash
ls


Datasets.ipynb
LICENSE
Magic Commands.ipynb
README.md
Resources.md
Untitled.ipynb
environment.yml
tutorials

In [20]:
%%javascript
alert( 'Hello, world!' );



In [23]:
%%ruby
puts 'Hello World!'


Hello World!

In [25]:
%%html
<button type="button">Click Me!</button>



In [ ]: